﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>生产工艺</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
    
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
     <li class="layui-nav-item" style="float:left;">
            <button id="btn-sync" type="button" onclick="SaveMainData()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1005;</i>数据保存
            </button>
        </li>
        <li class="layui-nav-item" style="float:left; margin-left:3%">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1007;</i>关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-card" style="margin-top:10px">
        <div class="layui-card-body ">
            <form class="layui-form" id="mForm">
                <div class="layui-form-item" style="margin-left:3%">
                    <div class="layui-input-inline" >
                        <input type="text" name="gyName" placeholder="工艺名称" class="layui-input" id="gyName" style="width:225%">
                    </div>
                    <div class="layui-input-inline" style="margin-left:40%">
                        <input type="hidden" name="keyCode"  class="layui-input" id="keyCode">
                        <input type="hidden" name="gxCode" id="gxCode">
                    </div>
                </div>
                <div class="layui-form-item" style="margin-left:3%">
                    <div class="layui-input-inline" >
                        <select id="relationCode" name="relationCode" lay-filter="sp">
                            <option value="">选择数据</option>
                        </select>
                        <input type="hidden" name="relationName" id="relationName">
                       
                    </div>
                    <div class="layui-input-inline" style="margin-left:5%">
                        <input type="text" name="versionCode" placeholder="工艺版本号" class="layui-input" id="versionCode">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="margin-left:3%">
                        <input type="text" name="memo" placeholder="备注说明" class="layui-input" id="versionCode">
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card" style="margin-top:6px">
        <div class="layui-card-body ">
            <div id="fDiv">
            </div>
        </div>
    </div>
   
</body>
</html>
<script src="~/js/framework/gongyijs.js"></script>
<script>
    var keyCode = "", reCode = "", version = "",gyName="",memo="";
    var proCode = "";
    $(function () {
        keyCode = getUrlVariable("keyCode");
        reCode = getUrlVariable("reCode");
        version = getUrlVariable("version");
        gyName = getUrlVariable("gyName");
        memo = getUrlVariable("memo");
        if(keyCode=="" || keyCode==undefined){
            keyCode = dateTimeStr;
        }
        $("input[name='keyCode']").val(keyCode);
        if (version != "" && version != undefined) {
            $("input[name='versionCode']").val(version);
        }
        if (gyName != "" && gyName != undefined) {
            $("input[name='gyName']").val(gyName);
        }
        if (memo != "" && memo != undefined) {
            $("input[name='memo']").val(memo);
        }
        ProcessProducts(reCode);
        ProcessByCode(reCode, keyCode);
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(sp)', function (data) {
                if(data.value!=""){
                    $('#fDiv').empty();
                    $("input[name='relationName']").val($("#relationCode option:selected").text());
                    ProcessByCode(data.value,keyCode);
                
                }
              
            });

        });
    })
    layui.use('element', function () {
        var $ = layui.jquery
            , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        element.on('tab(gyTab)', function (data) {
            showTab=this.getAttribute('lay-id');
            $("input[name='gxCode']").val(showTab);
            loadGyForm(showTab, $("#relationCode").val(), "div" + showTab);
        });
    });
    /**
     * 工序存货
     * **/
    function ProcessProducts(reCode) {
        $.ajax({
            url: "../ProductSet/GetProcessProduct",
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    var datas = rsl.data;
                    for (var i = 0; i < datas.length; i++) {
                        $("#relationCode").append("<option value='" + datas[i]["relationCode"] + "' >" + datas[i]["relationName"]+"(" +datas[i]["relationCode"]+")"+ "</option>");
                    }
                    if (reCode != undefined && reCode != "") {
                        $("#relationCode option[value = '" + reCode + "'] ").attr("selected", true);
                    }
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            }
        });
    }

    function SaveMainData() {
        $.ajax({
            url: "../ProductSet/SaveGyMainData",
            data: { datas: JSON.stringify(FormToJson("mForm")) },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("保存成功");
                }
            }
        });
    }
    function ProcessByCode(reCode,keyCode) {
        $.ajax({
            url: "../ProductSet/loadProcessGx",
            data: { reCode: reCode},
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                 loadGxTab(rsl.data, "fDiv", false);
                 loadGyForm(showTab,reCode,"div"+showTab);
                }
            }
        });
    }

    function GetFormValue() {
        var json = {
            gxCode: showTab,
            relationCode: $("#relationCode").val(),
            keyCode: $("#keyCode").val(),
            version: $("#versionCode").val(),
        }
        var msg = JSON.stringify(json);
            $.ajax({
                url: "../ProductSet/GetStandardByCode",
                data: { datas:msg },
                dataType: "json",
                type: "POST",
                success: function (rsl) {
                    if (rsl.result) {
                        var sData = rsl.data;
                        SetStandardValue(sData);
                    }
                }
            });
      
    }
    /**
     * 保存工艺表单数据
     * **/
    function SaveFormData(formId){
        var fData = JSON.stringify(FormToJson("f" + formId));
        var mData = JSON.stringify(FormToJson("mForm"));
        $.ajax({
            url: "../ProductSet/SaveGyStandard",
            data: { mData: mData, fData: fData },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("保存成功");
                } else {
                    layer.msg(rsl.message);
                }
            }
        });
    }
</script>

